<template>
    <div>

        <h1>房号增加</h1>
        <table class="table table-bordered">
            <tr>
                <td>房型名称</td>
                <td>
                    <input type="text" v-model="t.name">
                </td>
            </tr>
            <tr>
                <td>房型</td>
                <td>
                    <select v-model="t.test">
                        <option value="">--请选择--</option>
                        <option value="标准型">标准型</option>
                        <option value="商务型">商务型</option>
                        <option value="私人行">私人行</option>
                        <option value="单人型">单人型</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>房态</td>
                <td>
                    <select v-model="t.houseT">
                        <option value="">--请选择--</option>
                        <option value="空闲">空闲</option>
                        <option value="入住">入住</option>
                        <option value="维修">维修</option>
                    </select>
                </td>

            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="增加" class="btn btn-primary" @click="add">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';

let router = useRouter();
let route = useRoute();

let data: any = reactive({
    t: {
        "name": "",
        "test": "",
        "houseT": "",
        "state": 0
    },
});

let { t } = toRefs(data);

const add = () => {

    if (t.value.name == "") {
        alert("请输入房号");
        return;
    }
    if (t.value.test == "") {
        alert("请输入房型");
        return;
    }
    if (t.value.houseT == "") {
        alert("请选择房态");
        return;
    }
    let obj = {
        "name": t.value.name,
        "test": t.value.test,
        "houseT": t.value.houseT,
        "state": 0

    }
    axios({
        url: '/api/HouseNumber/HouseAdd',
        method: 'post',
        data: obj
    }).then((res) => {
        if (res.data.data == -1) {
            alert('名称重复');
            return;
        }
        else if (res.data.data == 1) {
            alert('添加成功');
            router.push('/listn');
        }
        else {
            alert('添加失败');
            return;
        }

    }).catch((err) => {
        console.log(err);
    })

}


</script>

<style scoped></style>